package com.sketch.commom;

import lombok.Data;

@Data
public class Result<T> {
	private String msg;
	private int status;
	private T data;

	public static <T> Result<T> success() {
		return new Result<T>()
				.withCode(CodeMsg.SUCCESS.getCode())
				.withMsg(CodeMsg.SUCCESS.getMsg());
	}

	public static <T> Result<T> success(T data) {
		return new Result<T>()
				.withCode(CodeMsg.SUCCESS.getCode())
				.withMsg(CodeMsg.SUCCESS.getMsg())
				.withData(data);
	}

	public static <T> Result<T> error(CodeMsg codeMsg) {
		return new Result<T>()
				.withCode(codeMsg.getCode())
				.withMsg(codeMsg.getMsg());
	}

	public static <T> Result<T> error(String msg) {
		return new Result<T>()
				.withCode(CodeMsg.EXCEPT.getCode())
				.withMsg(msg);
	}

	public static <T> Result<T> error(Integer code,String msg) {
		return new Result<T>()
				.withCode(code)
				.withMsg(msg);
	}



	public static <T> Result<T> error() {
		return new Result<T>()
				.withCode(CodeMsg.EXCEPT.getCode())
				.withMsg("操作失败");
	}

	public Result<T> withCode(int code) {
		setStatus(code);
		return this;
	}

	public Result<T> withMsg(String msg) {
		setMsg(msg);
		return this;
	}

	public Result<T> withData(T data) {
		setData(data);
		return this;
	}
}